# encoding: utf-8
# @project: st2111 
# @file: selenium_example9.py
# @time: 2023/6/1 15:05
# @author: abcque
# @license: (C) Copyright 2013-2021
# @contact: abcque@outlook.com
# @IDE: PyCharm
# @desc:
import time

from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

if __name__ == "__main__":
    url = "https://www.jd.com"
    executable_path = "../drivers/chromedriver.exe"

    service = Service(executable_path=executable_path)
    brower = webdriver.Chrome(service=service)

    brower.maximize_window()

    brower.get(url=url)

    # 定位查找目标元素
    element = brower.find_element(by=By.ID, value="key")

    # 在元素上模拟键盘输入
    element.send_keys("华为 P90")
    time.sleep(10)
    # 模拟按下回车键
    # element.send_keys(Keys.ENTER)
    # 模拟发送 Ctrl + A，选中输入的内容
    element.send_keys(Keys.CONTROL, "a")
    time.sleep(3)
    # 模拟发送 Ctrl + X，剪切选中的内容
    element.send_keys(Keys.CONTROL,"x")

    element.send_keys(Keys.F1)
    time.sleep(10)
    element.send_keys(Keys.F11)
    time.sleep(10)
    brower.quit()
